package com.vint.leetcode;

import com.vint.common.TreeNode;

/*
 * 1. done
 * 2. easy
 * 3. tree, 递归
 * 判断两棵树是否相等
 */
public class Leetcode100 {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if(null==p&&q==null){
            return true;
        }
        if(null==p||null==q){
            return false;
        }
        if(p.val==q.val){
            return isSameTree(p.left,q.left)&&isSameTree(p.right,q.right);
        }
        return false;

    }
    public static void main(String[] args) {
        Leetcode100 leetcode100= new Leetcode100();
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.left.left = new TreeNode(5);
        root.right = new TreeNode(4);
        root.right.right= new TreeNode(2);
        TreeNode root1 = new TreeNode(1);
        root1.left = new TreeNode(2);
        root1.left.left = new TreeNode(5);
        root1.right = new TreeNode(4);
        root1.right.right= new TreeNode(3);
        System.out.println(leetcode100.isSameTree(root,root1));
    }
  }
